﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ClassLibrary.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblGroupDAO
    {
         private DBService _db = null;
          public TblGroupDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }

          public DataTable GetGroup()
          {
              try
              {

                  DataTable dt = null;
                  return dt = _db.ExeSP_DataTable("Select * from TblGroup", false, CommandType.Text);
              }

              catch (Exception ex)
              {
                  throw ex;
              }
          }

          public TblGroup GetGroupID(int IDGroup)
          {
              TblGroup Group = new TblGroup();
              try
              {
                  DataTable dt = null;
                  dt = _db.ExeSP_DataTable("select * from TblGroup where IDGroup = @IDGroup",
                      new string[] { "@IDGroup" },
                      new object[] { IDGroup }
                      , CommandType.Text);
                  foreach (DataRow dr in dt.Rows)
                  {

                      Group.IDGroup = Convert.ToInt32(dr["IDGroup"]);
                      Group.GroupName = dr["GroupName"].ToString();
                  }
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              return Group;
          }
    }
}
